#pragma once
#include<iostream>
#include<unistd.h>
#include<vector>
#include <functional>


using work_t = std::function<void()>;
class Task
{
public:
    Task()
    {
        _work.push_back([](){
            std::cout<<"保存数据任务......"<<std::endl;
            sleep(1);
        });
        _work.push_back([](){
            std::cout<<"删除冗余数据......"<<std::endl;
            sleep(1);
        });
        _work.push_back([](){
            std::cout<<"计算处理数据......"<<std::endl;
            sleep(1);
        });
        _work.push_back([](){
            std::cout<<"打开指定数据......"<<std::endl;
            sleep(1);
        });
        
    }
    int slectNum()
    {
        return rand()%_work.size();
    }

    void runTask(int n)
    {
        if(n >= (int)_work.size() || n<0)
        {
            std::cerr<<"runTask(int n)输入错误"<<std::endl;
            return ;
        }
        _work[n]();
    }

private:
    std::vector<work_t> _work;//工作数组
};